package top.zsyle.sycc.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.zsyle.sycc.dto.SmsCodeDto;
import top.zsyle.sycc.result.JsonResult;
import top.zsyle.sycc.service.VerifyCodeService;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 请求获取图片验证码
     * @param imageCodeKey
     * @return
     */
    @GetMapping("/image/{imageCodeKey}")
    public JsonResult graph(@PathVariable("imageCodeKey") String imageCodeKey){
        String base64Graph = verifyCodeService.graph(imageCodeKey);
        return JsonResult.success(base64Graph);
    }

    /**
     * 请求获取短信验证码
     * @param dto
     * @return
     */
    @PostMapping("/smsCode")
    public JsonResult smsCode(@RequestBody @Valid SmsCodeDto dto){
        verifyCodeService.smsCode(dto);
        return JsonResult.success();
    }
//
//    /**
//     * 短信验证码登录：请求验证码
//     * @param dto
//     * @return
//     */
//    @PostMapping("/smsCodeLogin")
//    public JsonResult smsCodeLogin(@RequestBody @Valid SmsCodeDto dto){
//        verifyCodeService.smsCodeLogin(dto);
//        return JsonResult.success();
//    }
//
//    /**
//     * 请求获取 邮箱验证码
//     * @param dto
//     * @return
//     */
//    @PostMapping("/emailCode")
//    public JsonResult emailCode(@RequestBody @Valid EmailCodeDto dto){
//        verifyCodeService.emailCode(dto);
//        return JsonResult.success();
//    }
}
